<template>
	<view class="top topPage" :style="{'paddingTop': statusBarHeight+'px'}">
		<view class="content">
			<image mode="widthFix" src="@/static/logo.png"></image>
			<image mode="widthFix" @click="rightFn" class="zhed" src="@/static/zhed.png"></image>
			<view class="type">
				<view class="item" :class="item.path == path?'select':''" v-for="(item, index) in typeList" :key="index"
					@click="typeClick(item)">
					{{ item.text }}
				</view>
			</view>
		</view>
		<uni-popup ref="popup" background-color="#fff">
			<view class="popup-content" :style="{'paddingTop': statusBarHeight+'px'}">
				<view class="type">
					<view class="item" :class="item.path == path?'select':''" v-for="(item, index) in typeList"
						:key="index" @click="typeClick(item)">
						{{ item.text }}
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import utils from '@/utils/util.js'
	import storage from '@/storage/storage.js'
	import config from '@/config/config.js'
	export default {
		props: {
			path: {
				type: String,
				default: 'home'
			}
		},
		data() {
			return {
				typeList: [{
					text: '首页',
					path: 'home',
				}, {
					text: '关于',
					path: 'about',
				}, {
					text: '产品',
					path: 'product',
				}, {
					text: '应用',
					path: 'area',
				}, {
					text: '新闻',
					path: 'news',
				}, {
					text: '联系',
					path: '',
				}],
				windowWidth: config.windowWidth,
				statusBarHeight: 0
			}
		},
		created() {
			this.statusBarHeight = utils.statusBarHeight()
		},
		methods: {
			rightFn() {
				this.$refs.popup.open('right')
			},
			typeClick(val) {
				this.$refs.popup.close()
				if (!val.path) {
					uni.pageScrollTo({
						scrollTop: 9999999, //滚动到页面的目标位置（单位px）
						// duration: 0 //滚动动画的时长，默认300ms，单位 ms
					});
				} else {
					uni.navigateTo({
						url: `/pages/${val.path}/src/main`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.top {
		background: #fff;

		.content {
			display: flex;
			align-items: center;
			width: 90%;
			margin: 0 auto;
			height: 114px;

			image {
				width: 157px;
				margin-right: 15%;
			}

			.zhed {
				display: none;
			}

		}

		.type {
			display: flex;
			align-items: center;
			height: 100%;

			.item {
				margin-right: 40px;
				font-size: 20px;
				font-family: MicrosoftYaHei-, MicrosoftYaHei;
				font-weight: normal;
				color: #3E3A39;
			}

			.item.select {
				color: #273CFF;
			}
		}

		.popup-content {
			.type {
				width: 40vw;
				display: block;
				padding: 20px;

				.item {
					text-align: center;
					margin: 10px 0;
				}
			}
		}
	}
</style>